﻿using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Generic;
using System.Text;

namespace SX.Core.Auth
{
    /// <summary>
    /// 用户登录信息
    /// </summary>
    public class LoginInfo : ILoginInfo
    {
        private readonly IHttpContextAccessor _accessor;

        public LoginInfo(IHttpContextAccessor accessor)
        {
            _accessor = accessor;
        }
        /// <summary>
        /// 用户Id
        /// </summary>
        public virtual string UserId
        {
            get
            {
                var id = _accessor?.HttpContext?.User?.FindFirst(ClaimNames.UserId);
                if (id != null && id.Value.NotNull())
                {
                    return id.Value;
                }
                return string.Empty;
            }
        }
        /// <summary>
        /// 用户名
        /// </summary>
        public virtual string UserName
        {
            get
            {
                var name = _accessor?.HttpContext?.User?.FindFirst(ClaimNames.UserName);

                if (name != null && name.Value.NotNull())
                {
                    return name.Value;
                }

                return "";
            }
        }

      

    }
}
